<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>无标题文档</title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css"/>
    <link href="../../css/select.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../js/jquery.js"></script>
    <script type="text/javascript" src="../../js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="../../js/select-ui.min.js"></script>
    <script type="text/javascript" src="../../editor/kindeditor.js"></script>
    <script type="text/javascript" src="../../js/laydate/laydate.js"></script>
    <script type="text/javascript">
        /* KE.show({
             id : 'content7',
             cssPath : './index.css'
         });*/
    </script>
    <script type="text/javascript">


        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });
            $(".select2").uedSelect({
                width: 167
            });
            $(".select3").uedSelect({
                width: 100
            });

            /*$("#roomtype").change(function(){
                //$("#roomid option:eq(0)").val(3);
                //alert($("#roomid option:eq(0)").text());
                var $roomtype=$(this).val();
                $("#roomid").empty();
                $.getJSON("getAvaliableRoom.s",{"roomtype":$roomtype},function(data){
                    //alert(data[0].roomnumber);
                    //alert(data.length);
                    var json=data;
                    var html="";
                    $("#roomid option:gt(0)").remove();
                    $("#roomid").html("<option>请选择</option>;");
                    for(var i=0;i<json.length;i++){
                        html=html+'<option value="'+json[i].roomnumber+'">'+json[i].roomnumber+'</option>';
                    }
                    $("#roomid").append(html);
                });
            });*/

            //自动填充押金
            $("#roomNumber").change(function () {
                var roomNumber = $(this).val();
                //alert($roomnumber);
                $.getJSON("../../check/getDepositByRoomNumber",
                    {"roomNumber": roomNumber},
                    function (data) {
                        $("[name='money']").val(data.data.deposit);
                    });
            });

            $("#idCard").blur(function () {
                var btn = $("<input type='button' id='testBtn' value='注册'>");

                var idCard = $(this).val();
                $.getJSON("../../check/getVipByIdCard",
                    {"idCard": idCard},
                    function (data) {
                        if (data.state == 1) {
                            $("#checkuser").text("查无此人，请注册");
                            $("#checkuser").append(btn);
                            addBtnEvent("testBtn");
                        } else {
                            alert(data.data.name);
                            $("[name='username']").val(data.data.name);
                            $("#checkuser").html("&nbsp;");
                            $("[name='sex']").attr("checked", false);
                            var $s = data.data.sex;
                            //alert(data.sex);
                            if ($s == "男") {
                                //alert($s);
                                $("[value='男']").attr("checked", true);
                            }
                            if ($s == "女") {
                                $("[value='女']").attr("checked", true);
                            }

                            $("[name='phone']").val(data.data.phone);
                            $("[name='vipid']").val(data.data.vipId);
                        }
                    });
            });
            $("[type='button']").click(function () {
                var date = new Date();
                var seperator1 = "-";
                var seperator2 = ":";
                var month = date.getMonth() + 1;
                var strDate = date.getDate();
                var strMinutes = date.getMinutes();
                var strHour = date.getHours();
                var strSecond = date.getSeconds();
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = "0" + strDate;
                }
                if (strHour >= 0 && strHour <= 9) {
                    strHour = "0" + strHour;
                }
                if (strSecond >= 0 && strSecond <= 9) {
                    strSecond = "0" + strSecond;
                }
                if (strMinutes >= 0 && strMinutes <= 9) {
                    strMinutes = "0" + strMinutes;
                }
                var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                    + " " + strHour + seperator2 + strMinutes
                    + seperator2 + strSecond;
                var roomNumber = $("#roomNumber").val();
                var vipid = $("#vipid").val();
                var userName = $("#username").val();
                var sex = $("input[name='sex']:checked").val();
                var idCard = $("#idCard").val();
                var phone = $("[name='phone']").val();
                var checkInTime = currentdate;
                var roomtype = $("#roomtype option:selected").val();
                alert(roomtype);
                var roomtypestr = $("#roomtype option:selected").text();
                alert(roomtypestr);
                alert(checkInTime);
                console.log(checkInTime);
                $.ajax({
                    url: "../../check/insertCheck",
                    type: "POST",
                    traditional: true,
                    data: {
                        roomNumber: roomNumber,
                        vipid: vipid,
                        userName: userName,
                        sex: sex,
                        idCard: idCard,
                        phone: phone,
                        checkInTime: checkInTime,
                        roomtype: roomtype,
                        roomtypestr: roomtypestr
                    },

                    success: function (data) {
                        alert("添加成功");
                        console.log("添加成功");

                        window.location = "inroominfo.html";

                    }
                })

            });

            /* $("#form1").submit(function(){
                 if($("#roomtype").val()==0||$("#roomNumber").val()==0||$("#idCard").val()==""||$("#username").val()==""){
                     alert("请填写正确的信息");
                     return false;
                 }
                 else{
                     return true;
                 }
             });*/

        });

        function addBtnEvent(id) {
            $("#testBtn").bind("click", function () {
                window.location = "../vip/addvip.html";
            });
        }
    </script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">入住信息管理</a></li>
        <li><a href="#">添加入住信息</a></li>
    </ul>
</div>

<div class="formbody">
    <div class="formtitle"><span>入住信息</span></div>
    <div id="usual1" class="usual">
        <div id="tab1" class="tabson">
            <ul class="forminfo">
                <li>
                    <label>房间类型<b>*</b></label>
                    <div class="vocation">
                        <!-- <p id="p1"></p>-->

                        <select class="select1" id="roomtype" onchange="change()">
                            <option>请选择房间类型</option>
                        </select>
                    </div>
                    <script>
                        $(function () {
                            $.ajax({
                                url: '../../roomtype/getAllRoomType',
                                type: "post",
                                async: false,
                                data: {},
                                success: function (data) {
                                    var option;
                                    var headOption = "";
                                    for (var i = 0; i < data.data.length; i++) {
                                        headOption = headOption + "<option value='" + data.data[i].rid + "'>" + data.data[i].type + "</option>";
                                    }
                                    option = '<select  name="roomtype" size="1" id="roomType" style="width:100px;"><option value="" onselect="onselect">请选择</option>' +
                                        headOption + '</select>';

                                    $("#roomtype").html(option);
                                }
                            })
                        })
                    </script>

                </li>
                <li>
                    <label>房间号<b>*</b></label>
                    <div class="vocation">
                        <select class="select1" name="roomNumber" id="roomNumber">
                            <option id="option0">请选择</option>
                        </select>
                    </div>
                    <script>
                        function change() {
                            var roomtype = $("#roomtype").val();
                            console.log(roomtype);
                            $.ajax({
                                url: '../../check/getRoomNumberByRoomType',
                                type: "post",
                                data: {'roomType': roomtype},
                                success: function (data) {
                                    var option;
                                    var headOption = "";
                                    for (var i = 0; i < data.data.length; i++) {
                                        headOption = headOption + "<option value='" + data.data[i] + "'>" + data.data[i] + "</option>";
                                    }
                                    option = '<select  name="roomNumber" size="1" id="roomNumber" style="width:100px;"><option value="" onselect="onselect">请选择</option>' +
                                        headOption + '</select>';

                                    $("#roomNumber").html(option);
                                }
                            })
                        }
                    </script>
                </li>
                <br/>
                <li>
                    <label for="idCard">身份证号码<b>*</b></label>
                    <div class="vocation">
                        <input name="idCard" id="idCard" type="text" class="dfinput" placeholder="请填写客户身份证号码"
                               style="width:344px;"/>
                    </div>
                    <span style="color:red;font-size: 21px" id="checkuser">&nbsp; </span>
                </li>


                <li style="margin-top:20px;">
                    <label for="username">客人姓名<b>*</b></label>
                    <div class="vocation">
                        <input readonly="readonly" name="username" id="username" type="text" class="dfinput"
                               placeholder="请填写客户姓名" style="width:344px;"/>
                        <input type="hidden" name="vipid" id="vipid" value="">
                    </div>
                </li>
                <br/>
                <li>
                    <label for="sex">性别<b>*</b></label>
                    <div class="vocation" style="padding-top: 10px;">
                        <input readonly="readonly" name="sex" type="radio" value="男" checked="checked"/>
                        男&nbsp;&nbsp;&nbsp;&nbsp;
                        <input readonly="readonly" name="sex" type="radio" value="女"/>
                        女
                    </div>
                </li>
                <br/>

                <li>
                    <label for="phone">手机号码<b>*</b></label>
                    <div class="vocation">
                        <input readonly="readonly" name="phone" type="text" class="dfinput" placeholder="请填写客户手机号码"
                               style="width:344px;"/>
                    </div>
                </li>
                <br/>
                <li>
                    <label for="money">押金<b>*</b></label>
                    <div class="vocation">
                        <input readonly="readonly" name="money" type="text" class="dfinput" placeholder="输入押金金额"
                               style="width:344px;"/>
                    </div>
                </li>
                <br/>
                <li>
                    <label for="date">入住时间<b>*</b></label>
                    <div class="vocation">
                        <input type="text" class="laydate-icon span1-1" id="Calendar"
                               style="width:324px; height:30px; line-height:28px; text-indent:10px; "/>
                    </div>
                </li>
                <br/>
                <li>
                    <label>&nbsp;</label>
                    <input name="" type="button" class="btn" value="入住"/>
                </li>
            </ul>
        </div>
    </div>
    <script type="text/javascript">

        $("#usual1 ul").idTabs();
    </script>
    <script type="text/javascript">
        $('.tablelist tbody tr:odd').addClass('odd');

        !function () {
            laydate.skin('qianhuang');
            laydate({elem: '#Calendar'});
            laydate.skin('qianhuang');
            laydate({elem: '#Calendar2'});
        }();
        $(function dd() {
            var d = new Date(), str = "";
            str += (d.getFullYear() + "-");
            str += "0";
            str += (d.getMonth() + 1 + "-");
            str += d.getDate();
            $("#Calendar").attr("value", str);
            $("#Calendar2").attr("value", str);
        });

    </script>
</div>
</body>
</html>
